package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyMdCaiwu;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdCaiwuParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdFuzhumxzParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyMdFuzhumxzResult;
import cn.stylefeng.guns.sys.modular.system.model.result.OrderDataResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdCaiwuService;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdFuzhumxzService;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdLirunbiaoService;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdZichanfzbService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ErrorResponseData;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * 门店财务主表控制器
 *
 * @author jiangge
 * @Date 2021-09-08 10:50:59
 */
@Controller
@RequestMapping("/btyMdCaiwu")
public class BtyMdCaiwuController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(BtyMdCaiwuController.class);
    private String PREFIX = "/modular/system/btyMdCaiwu";

    @Autowired
    private BtyMdCaiwuService btyMdCaiwuService;
    @Autowired
    private BtyMdZichanfzbService btyMdZichanfzbService;
    @Autowired
    private BtyMdLirunbiaoService btyMdLirunbiaoService;
    @Autowired
    private BtyMdFuzhumxzService btyMdFuzhumxzService;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyMdCaiwu.html";
    }

    /**
     * 新增页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyMdCaiwu_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyMdCaiwu_edit.html";
    }


    /**
     * 新增接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyMdCaiwuParam btyMdCaiwuParam) {
        this.btyMdCaiwuService.add(btyMdCaiwuParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyMdCaiwuParam btyMdCaiwuParam) {
        this.btyMdCaiwuService.update(btyMdCaiwuParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyMdCaiwuParam btyMdCaiwuParam) {
        this.btyMdCaiwuService.delete(btyMdCaiwuParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyMdCaiwuParam btyMdCaiwuParam) {
        BtyMdCaiwu detail = this.btyMdCaiwuService.getById(btyMdCaiwuParam.getBtyMdCaiwuId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyMdCaiwuParam btyMdCaiwuParam) {
        return this.btyMdCaiwuService.findPageBySpec(btyMdCaiwuParam);
    }

    /**
     * 导入资产负债表
     */
    @RequestMapping("/importZcfzb")
    @ResponseBody
    public ResponseData importZcfzb(@RequestParam("file") MultipartFile file) {
        ResponseData data = new ResponseData();
        try {
            data = this.btyMdCaiwuService.importZcfzb(file);
        } catch (Exception e) {
            e.printStackTrace();
            return ErrorResponseData.error("导入失败！");
        }
        return data;
    }

    /**
     * 导入损益表
     */
    @RequestMapping("/importSyb")
    @ResponseBody
    public ResponseData importSyb(@RequestParam("file") MultipartFile file) {
        ResponseData data = new ResponseData();
        try {
            data = this.btyMdCaiwuService.importSyb(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.success();
    }

    /**
     * 点击查看资产负债表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/viewZcfzb")
    public String viewZcfzb(Model model,BtyMdCaiwuParam param) {
        model.addAttribute("param", param);
        return PREFIX + "/btyMdCaiwu_viewZcfzb.html";
    }

    /**
     * 点击查看损益表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/viewLrb")
    public String viewLrb(Model model,BtyMdCaiwuParam param) {
        model.addAttribute("param", param);
        return PREFIX + "/btyMdCaiwu_viewLrb.html";
    }


    /**
     * app查询-资产负债表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllZcfzbData", method = RequestMethod.GET)
    public LayuiPageInfo findAllZcfzbData(BtyMdCaiwuParam param) {
        List<OrderDataResult> detail = this.btyMdZichanfzbService.findAllZcfzbData(param);
        int total = detail.size();
        LayuiPageInfo layuiPageInfo = new LayuiPageInfo();
        layuiPageInfo.setData(detail);
        layuiPageInfo.setCount(total);
        return layuiPageInfo;
    }

    /**
     * app查询-损益表(即利润表)
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllLirunData", method = RequestMethod.GET)
    public LayuiPageInfo findAllLirunData(BtyMdCaiwuParam param) {
        List<OrderDataResult> detail = this.btyMdLirunbiaoService.findAllLirunData(param);
        int total = detail.size();
        LayuiPageInfo layuiPageInfo = new LayuiPageInfo();
        layuiPageInfo.setData(detail);
        layuiPageInfo.setCount(total);
        return layuiPageInfo;
    }



    /**
     * app查询-费用明细
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllFzmxzData", method = RequestMethod.GET)
    public LayuiPageInfo findAllFzmxzData(BtyMdFuzhumxzParam param) {
        List<BtyMdFuzhumxzResult> detail = this.btyMdFuzhumxzService.findAllFzmxzData(param);
        int total = detail.size();
        LayuiPageInfo layuiPageInfo = new LayuiPageInfo();
        layuiPageInfo.setData(detail);
        layuiPageInfo.setCount(total);
        return layuiPageInfo;
    }

    /**
     * 导入正规损益表
     */
    @RequestMapping("/importSybzg")
    @ResponseBody
    public ResponseData importSybzg(@RequestParam("file") MultipartFile file) {
        ResponseData data = new ResponseData();
        try {
            data = this.btyMdCaiwuService.importSybzg(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.success();
    }

    /**
     * 点击查看正规损益表
     *
     * @Date 2022-05-11
     */
    @RequestMapping("/viewLrbzg")
    public String viewLrbzg(Model model,BtyMdCaiwuParam param) {
        model.addAttribute("param", param);
        return PREFIX + "/btyMdCaiwu_viewLrbzg.html";
    }

    /**
     * 查询正规损益表
     *
     * @Date 2022-05-11
     */
    @ResponseBody
    @RequestMapping(value = "/findAllLirunzgData", method = RequestMethod.GET)
    public LayuiPageInfo findAllLirunzgData(BtyMdCaiwuParam param) {
        List<OrderDataResult> detail = this.btyMdLirunbiaoService.findAllLirunzgData(param);
        int total = detail.size();
        LayuiPageInfo layuiPageInfo = new LayuiPageInfo();
        layuiPageInfo.setData(detail);
        layuiPageInfo.setCount(total);
        return layuiPageInfo;
    }
}


